package 牛客.链表;

import 剑指offer.ListNode;

import java.util.ArrayDeque;
import java.util.Deque;

public class BM13判断一个链表是否为回文结构 {
    public boolean isPail (ListNode head) {
        // write code here
        if (head.next==null) {
            return true;
        }

        Deque<ListNode> stack=new ArrayDeque<>();
        ListNode cur=head;
        while (cur!=null) {
            stack.push(cur);
            cur=cur.next;
        }

        cur=head;
        while (cur!=null) {
            if (cur.val!=stack.pop().val) {
                return false;
            }
            cur=cur.next;
        }
        return true;
    }
}
